---
title: "Table A.11"
output: 
---

# Table A.11

# Who's to Blame? Postconflict Violence and Public Attitudes Towards Peace Agreements
# Wyer, Frank. 

#clear environment
```{r clear environment}
rm(list = ls())
```

# uncomment and set working directory to replication archive
# setwd("~/blame_replication")

# Uncomment to install packages if necessary
# install.packages("tidyverse")
# install.packages("estimatr")
# install.packages("texreg")

#load packages
```{r}
library(tidyverse)
library(estimatr)
library(texreg)
```

#read in data
```{r}
survey_clean <- read.csv("survey_clean.csv")
```

#create binary variable for security trajectory
```{r generate security trajectory variable}
survey_clean <- survey_clean %>% 
  mutate(homs_worse = ifelse(homratediff > 0, 1, 0))
```

#estimate models for conflict exposure measures with and without controls for respondents in control condition only
```{r estimate models in control group}
#farc presence
farc_het_cgroup <- lm_robust(outcomes_zscale ~ factor(farc_presence == 1), survey_clean %>% filter(treatment == "C"))
farc_het_cgroup_controls <- lm_robust(outcomes_zscale ~ factor(farc_presence == 1) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))

#security trajectory: homicide rate increased
sec_het_cgroup <- lm_robust(outcomes_zscale ~ factor(homs_worse == 1), survey_clean %>% filter(treatment == "C"))
sec_het_cgroup_controls <- lm_robust(outcomes_zscale ~ factor(homs_worse == 1) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))

#family displacement victims
victim_het_cgroup <- lm_robust(outcomes_zscale ~ factor(victimized == 1), survey_clean %>% filter(treatment == "C"))
victim_het_cgroup_controls <- lm_robust(outcomes_zscale ~ factor(victimized == 1) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))
```

#table - Heterogeneity in Control Group: Main Conflict Exposure Measures
```{r generate table}
texreg(list(farc_het_cgroup, farc_het_cgroup_controls, sec_het_cgroup, sec_het_cgroup_controls, victim_het_cgroup, victim_het_cgroup_controls), custom.coef.map = list("(Intercept)" = "(Intercept)", "factor(farc_presence == 1)TRUE" = "FARC Presence", "factor(homs_worse == 1)TRUE" = "Security Trajectory Worse", "factor(victimized == 1)TRUE" = "Family Displacement Victims"), digits = 2, include.ci = FALSE, single.row = FALSE, include.fstatistic = FALSE, include.rmse = FALSE, include.rsquared = FALSE, include.adjrs = FALSE, include.nobs = TRUE, stars = numeric(0), custom.gof.rows = list("Controls" = c("", "\\checkmark", "", "\\checkmark", "", "\\checkmark")), float.pos = "h", caption.above	= TRUE, caption = "Heterogeneity in Control Group: Main Conflict Exposure Measures")
```


